using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
namespace DAL
{
    public class Albums : DAL.DataManager<Album>
    {
        private static Albums Instance = new Albums();
        static Albums() { }

        public override string TableName
        {
            get { return @"awesome_albums"; }
        }

        protected override void CopyToItem(DataRow Row, Album Item)
        {
            Item.User = Users.Item(Convert.ToInt64(Row["UserID"]));

            Item.Name = Convert.ToString(Row["Name"]);
        }

        protected override void CopyFromItem(DataManagerQuery query, Album Item)
        {
            query.AddParam("UserID", Item.User.ID);

            query.AddParam("Name", Item.Name);
        }

        public static Album Item(Int64 id)
        {
            return Instance.GetItem(id);
        }

        public static List<Album> All()
        {
            return Instance.GetItems();
        }

        public static void Add(Album Item)
        {
            Instance.Insert(Item);
        }

        public static void Save(Album Item)
        {
            Instance.Update(Item);
        }

        public static List<Album> GetByUser(User user)
        {
            DataManagerQuery query = new DataManagerQuery();
            query.AddParam("UserID", user.ID);
            return Instance.GetItems(query);
        }
    }

    public class Album : DAL.DataManagerRow
    {
        private User _User;
        public User User
        {
            get
            {
                return _User;
            }
            set
            {
                _User = value;
            }
        }

        private string _Name;
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }

        public List<Photo> GetPhotos()
        {
            return Photos.GetByAlbum(this);
        }
    }
}